package ch.hslu.weather;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;

public class MyMapView extends MapView {

	private GeoPoint gp;
	private double latitude;
	private double longitude;
	private Main mapactivity;

	public MyMapView(Context context, String apiKey) {
		super(context, apiKey);
	}

	public void setMapactivity(Main mapactivity) {
		this.mapactivity = mapactivity;
	}

	public MyMapView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public MyMapView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		if (mapactivity.getOverlayMode() == Main.MODE_OVERLAY_ADD) {
			if (ev.getAction() == MotionEvent.ACTION_DOWN) {
				gp = getProjection().fromPixels((int) ev.getX(),
						(int) ev.getY());
				
				latitude = gp.getLatitudeE6() / 1E6;
				longitude = gp.getLongitudeE6() / 1E6;
				
				mapactivity.addCloud(gp);
				mapactivity.setOverlayMode(Main.MODE_OVERLAY_NONE);
			}
		}
		return super.onTouchEvent(ev);
	}

	public double getLatitude() {
		return latitude;
	}

	public double getLongitude() {
		return longitude;
	}

}
